package com.ambulance.project.manager.service.impl;

import com.ambulance.project.biz.entity.Dispatch;
import com.ambulance.project.biz.service.DispatchService;
import com.ambulance.project.biz.util.ScanFileUtil;
import com.ambulance.project.manager.domain.BizDispatchcase;
import com.ambulance.project.manager.mapper.BizDispatchcaseMapper;
import com.ambulance.project.manager.service.IBizDispatchcaseService;
import com.ambulance.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * 调度病例详细信息Service业务层处理
 *
 * @author zr
 * @date 2020-05-11
 */
@Service
public class BizDispatchcaseServiceImpl implements IBizDispatchcaseService {
    @Autowired
    private BizDispatchcaseMapper bizDispatchcaseMapper;
    @Autowired
    private DispatchService dispatchService;

    /**
     * 查询调度病例详细信息
     *
     * @param dispatchCaseID 调度病例详细信息ID
     * @return 调度病例详细信息
     */
    @Override
    public BizDispatchcase selectBizDispatchcaseById(Long dispatchCaseID) {
        final BizDispatchcase bizDispatchcase = bizDispatchcaseMapper.selectBizDispatchcaseById(dispatchCaseID);
        final File mp4 = ScanFileUtil.getTargetFile(bizDispatchcase.getDispatchID().toString(), "mp4");
       if(!CommonUtils.checkNull(mp4)){
           final Dispatch dispatch = new Dispatch();
           dispatch.setDispatchID(bizDispatchcase.getDispatchID().intValue());
           dispatch.setTreatContent( "/profile/videoPath/" + bizDispatchcase.getDispatchID() + "/" + mp4.getName());
           dispatchService.updateById(dispatch);
       }
        return bizDispatchcase;
    }

    /**
     * 查询调度病例详细信息列表
     *
     * @param bizDispatchcase 调度病例详细信息
     * @return 调度病例详细信息
     */
    @Override
    public List<BizDispatchcase> selectBizDispatchcaseList(BizDispatchcase bizDispatchcase) {
        return bizDispatchcaseMapper.selectBizDispatchcaseList(bizDispatchcase);
    }

    /**
     * 新增调度病例详细信息
     *
     * @param bizDispatchcase 调度病例详细信息
     * @return 结果
     */
    @Override
    public int insertBizDispatchcase(BizDispatchcase bizDispatchcase) {
        return bizDispatchcaseMapper.insertBizDispatchcase(bizDispatchcase);
    }

    /**
     * 修改调度病例详细信息
     *
     * @param bizDispatchcase 调度病例详细信息
     * @return 结果
     */
    @Override
    public int updateBizDispatchcase(BizDispatchcase bizDispatchcase) {
        return bizDispatchcaseMapper.updateBizDispatchcase(bizDispatchcase);
    }

    /**
     * 批量删除调度病例详细信息
     *
     * @param dispatchCaseIDs 需要删除的调度病例详细信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchcaseByIds(Long[] dispatchCaseIDs) {
        return bizDispatchcaseMapper.deleteBizDispatchcaseByIds(dispatchCaseIDs);
    }

    /**
     * 删除调度病例详细信息信息
     *
     * @param dispatchCaseID 调度病例详细信息ID
     * @return 结果
     */
    @Override
    public int deleteBizDispatchcaseById(Long dispatchCaseID) {
        return bizDispatchcaseMapper.deleteBizDispatchcaseById(dispatchCaseID);
    }
}
